#pragma once
#include <QObject>
#include <QTextStream>
#include <QFile>
#include <fstream>
#include "OOPException.h"

_NS_OOP_BEGIN

class Logger : public QObject
{
public:
	static const int DEBUG_OUT = 1;
	static const int STD_OUT = 2;
	static const int FILE_OUT = 4;

	~Logger ();

	static void setMode (int mode = DEBUG_OUT, const QString &logDir = "");
	static void info (const char *funcStr, const QString &msg);
	static void warning (const char *funcStr, const QString &msg);
	static void warning (const char *funcStr, const QString &msg, OOPException &e);
	static void critical (const char *funcStr, const QString &msg);
	static void critical (const char *funcStr, const QString &msg, OOPException &e);

private:
	int _mode;
	QFile _logFile;
	std::ofstream _outLogStream;
	static const int INCLUDE_DAY = 1;
	static const int INCLUDE_TIME = 2;
	static Logger _sLogger;

	Logger ();
	void _setMode (int mode, const QString &logDir);
	void _info (const char *funcStr, const QString &msg);
	void _warning (const char *funcStr, const QString &msg);
	void _warning (const char *funcStr, const QString &msg, OOPException &e);
	void _critical (const char *funcStr, const QString &msg);
	void _critical (const char *funcStr, const QString &msg, OOPException &e);
	QString _getTimeSimpleFormat (quint8 dayTimeFlag = INCLUDE_DAY | INCLUDE_TIME);
	QString _getTimeFullFormat (quint8 dayTimeFlag = INCLUDE_DAY | INCLUDE_TIME);
	void _outputMessage (const QString &msg);
};

_NS_OOP_END